<template>
  <div class="user-management-container">
    <el-form ref="form" label-width="200px" :model="form" :rules="rules">
      <el-form-item label="文章标题" prop="articleTitle">
        <el-input v-model="form.articleTitle" placeholder="请输入职位内容" />
      </el-form-item>
      <el-form-item label="文章内容" prop="articleContent">
        <fuwenben v-model="form.articleContent" />
      </el-form-item>
    </el-form>
    <el-button class="baocun" size="medium" type="primary" @click="save">
      保存
    </el-button>
  </div>
  <!-- 增加 -->
</template>

<script>
  /* eslint-disable*/
  import { doAdd } from '@/api/xieyi'

  import fuwenben from '../vab/editortwo/wang.vue'
  //import { number } from 'echarts'
  export default {
    name: 'search',
    components: {
      fuwenben,
    },
    data() {
      return {
        form: {},

        activated() {
          if (this.$refs.MaskVideo.src) this.$refs.MaskVideo.play()
        },
        deactivated() {
          if (this.$refs.MaskVideo.src) this.$refs.MaskVideo.pause()
        },
        rules: {
          articleTitle: [
            { required: true, trigger: 'blur', message: '请输入文章标题' },
          ],
          articleContent: [
            { required: true, trigger: 'blur', message: '文章内容不能为空' },
          ],
        },
        title: '',
        dialogFormVisible: false,
      }
    },
    created() {},
    methods: {
      showEdit(row) {
        if (!row) {
          this.title = '添加'
        } else {
          this.title = '编辑'
          this.form = Object.assign({}, row)
        }
        this.dialogFormVisible = true
      },
      close() {
        let userId = this.form.userId
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        if (!this.form.id) {
          this.form.userId = userId
        }

        this.dialogFormVisible = false
        this.imageUrl = ''
        this.imageUrltwo = ''
        // this.form = ''
      },

      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            if (this.form.id) {
              const msg = doEdit(this.form)
              console.log(msg)
              this.$baseMessage(msg, 'success', 'vab-hey-message-success')
              this.$emit('fetch-data')
              this.close()
            } else {
              const msg = doAdd(this.form)
              this.$emit('fetch-data')
              this.close()
              msg.then((res) => {
                console.log(res)
                if (res.msg === '添加成功') {
                  this.$baseMessage(
                    res.msg,
                    'success',
                    'vab-hey-message-success'
                  )
                  this.$router.push({ path: '/setting/notice/noticelist' })
                }
              })
            }
          }
        })
      },
    },
  }
</script>
<style>
  /* .huakuai {
    position: relative;
    left: 96%;
  } */
  .avatar-uploader .el-upload {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409eff;
  }
  .avatar-uploader-icon {
    width: 178px;
    height: 178px;
    font-size: 28px;
    line-height: 178px;
    color: #8c939d;
    text-align: center;
  }
  .avatar {
    display: block;
    width: 178px;
    height: 178px;
  }
  .baocun {
    width: 100%;
    height: 100%;
  }
</style>
